package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "购物车相关接口")
@RequestMapping("/user/shoppingCart")
@RestController
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("购物车添加接口")
    @PostMapping("/add")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO dto) {
        return shoppingCartService.addShoppingCart(dto);

    }

    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result list() {
        return shoppingCartService.list();
    }
    @ApiOperation("删除购物车中一个商品")
    @PostMapping("/sub")
    public Result delete(@RequestBody ShoppingCartDTO dto) {
        return shoppingCartService.delete(dto);
    }
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result clean(){
        return  shoppingCartService.clean();
    }
}
